﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using _MetalSlug.Form.ScreenSystem.Message;
namespace _MetalSlug.Form.ScreenSystem
{
    public class GameManager
    {
        static GameManager Instance;
        List<MyScreen> lstScreens;
        MyScreen CurrentScreen;

        private GameManager()
        {
            lstScreens = new List<MyScreen>();
        }

        public static GameManager GetInstance()
        {
            if(Instance == null)
            {
                Instance = new GameManager();
            }

            return Instance;
        }

        public MyScreen GetCurrentScreen()
        {
            return CurrentScreen;
        }

        public void Register(MyScreen Screen)
        {
            List<MyScreen> lstScreenEqual = lstScreens.Where(item => item.TypeOfWindow == Screen.TypeOfWindow).ToList();
            if(lstScreenEqual.Count == 0)
            {
                Screen.Manager = this;
                lstScreens.Add(Screen);
                if(Screen.TypeOfWindow == MyScreen.TYPE.MAINMENU)
                {
                    CurrentScreen = Screen;
                }
            }
        }

        public void Receive(MyScreen SendWindow, MyScreen.TYPE TypeReceiveWindow, MyMessage SendMessage)
        {
            MyScreen ScreenReceive = lstScreens.Where(item => item.TypeOfWindow == TypeReceiveWindow).Take(1).SingleOrDefault();
            if (ScreenReceive != null)
            {
                ScreenReceive.Receive(SendWindow, SendMessage);
            }

            if (SendMessage.TypeOfMessage == MyMessage.TYPE.SHOW)
            {
                CurrentScreen = ScreenReceive;
            }
        }
    }
}
